import menu from '@/config/menu'
export function isAuth(tableName, key) {
	let role = localStorage.getItem("UserTableName");
	if(!role){
		role = 'users'
	}
	let menus = menu.list()
	for(let i=0;i<menus.length;i++){
		if(menus[i].tableName==role){
			for(let j=0;j<menus[i].frontMenu.length;j++){
				for(let k=0;k<menus[i].frontMenu[j].child.length;k++){
					if(tableName==menus[i].frontMenu[j].child[k].tableName){
						let buttons = menus[i].frontMenu[j].child[k].buttons.join(',');
						return buttons.indexOf(key) !== -1 || false
					}
				}
			}
		}
	}
	return false;
}
export function isBackAuth(tableName, key) {
	let role = localStorage.getItem("UserTableName");
	let menus = menu.list()
	for(let i=0;i<menus.length;i++){
		if(menus[i].tableName==role){
			for(let j=0;j<menus[i].backMenu.length;j++){
				for(let k=0;k<menus[i].backMenu[j].child.length;k++){
					if(tableName==menus[i].backMenu[j].child[k].tableName){
						let buttons = menus[i].backMenu[j].child[k].buttons.join(',');
						return buttons.indexOf(key) !== -1 || false
					}
				}
			}
		}
	}
	return false;
}
/**
 *  * 获取当前时间（yyyy-MM-dd hh:mm:ss）
 *   */
export function getCurDateTime() {
	let currentTime = new Date(),
	year = currentTime.getFullYear(),
	month = currentTime.getMonth() + 1 < 10 ? '0' + (currentTime.getMonth() + 1) : currentTime.getMonth() + 1,
	day = currentTime.getDate() < 10 ? '0' + currentTime.getDate() : currentTime.getDate(),
	hour = currentTime.getHours(),
	minute = currentTime.getMinutes(),
	second = currentTime.getSeconds();
	return year + "-" + month + "-" + day + " " +hour +":" +minute+":"+second;
}

/**
 *  * 获取当前日期（yyyy-MM-dd）
 *   */
export function getCurDate() {
	let currentTime = new Date(),
	year = currentTime.getFullYear(),
	month = currentTime.getMonth() + 1 < 10 ? '0' + (currentTime.getMonth() + 1) : currentTime.getMonth() + 1,
	day = currentTime.getDate() < 10 ? '0' + currentTime.getDate() : currentTime.getDate();
	return year + "-" + month + "-" + day;
}

export function changeReturnGoods() {
	let type = false
	let menus = menu.list()
	for(let i=0;i<menus.length;i++){
		for(let j=0;j<menus[i].backMenu.length;j++){
			for(let k=0;k<menus[i].backMenu[j].child.length;k++){
				if('orders/已完成'==menus[i].backMenu[j].child[k].tableName){
					let buttons = menus[i].backMenu[j].child[k].buttons.join(',');
					if(buttons.indexOf('退货审核') !== -1){
						type = true
					}
				}
			}
		}
	}
	return type
}
